package com.example.newsapp.ui.components.mainComponent

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material3.DrawerState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.example.newsapp.data.compositionLocal.LocalDrawerEnabled
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

/**
 * 顶部菜单按钮
 *
 * @param scope 开启协程
 */
@Composable
fun TopMenuBar(
    scope: CoroutineScope,
    modifier: Modifier = Modifier
) {
    val drawerState = LocalDrawerEnabled.current
    IconButton (
        onClick = {
            scope.launch {
                if (drawerState.isClosed) drawerState.open() else drawerState.close()
            }
        }
    ) {
        Icon(Icons.Default.Menu, null)
    }
}